package everest3;
import everest3.utils.*;
import java.awt.event.*;
import java.text.*;
import java.util.*;
import javax.swing.*;
import javax.swing.JFormattedTextField;

import javax.swing.JFormattedTextField;
import javax.swing.JFormattedTextField;




/**
 * Custom button for entering dates. The <code>DateTextField/code> class
 * is just a standard button that defines an additional bound
 * property: "date". The button displays the date property as its
 * label. When clicked, it does not generate an
 * <code>ActionEvent</code>, but displays a {@link DateChooser} dialog
 * instead, that allows you to change the date. When the date is
 * changed, a <code>PropertyChangeEvent</code> is generated, according
 * the contract for bound properties.
 */
public class DateTextField extends JFormattedTextField
{
    /** Format to use to display the date property. */
    public  static final DateFormat DATE_FORMAT = new SimpleDateFormat("dd/MM/yyyy");

    /** DateChooser instance to use to change the date. */
    public static final DateChooser DATE_CHOOSER = new DateChooser((JFrame)null,"Seleccione la Fecha");

    /**
     * propiedad de fecha
     */
    public Date date;

    /**
     * constructor que me permite gestionar el formato del objeto
     * @param format formato de control de caracteres a ingresar
     */
    public DateTextField(Format format){
        super(format);
    }
    /**
     * constructor que me permite gestionar el formato del objeto
     * @param formatter formato de control de caracteres a ingresar
     */
    public DateTextField(JFormattedTextField.AbstractFormatter formatter){
        super(formatter);
    }

    /**
     * Called when the button is clicked, in order to fire an
     * <code>ActionEvent</code>. Displays the dialog to change the
     * date instead of generating the event and updates the date
     * property.
     *
     * @param e <code>ActionEvent</code> to fire
     **/
    protected void fireActionPerformed( ActionEvent e ) {
	Date newDate = DATE_CHOOSER.select(date);
	if ( newDate == null )
	    return;
	setDate( newDate );
    }



    /**
     * constructor a un nuevo objeto <code>DateTextField</code> con un formato de fecha
     * @param date initial date
     */
    public DateTextField( Date date ) {
	super( DATE_FORMAT.format(date) );
	this.date = date;
    }



    /**
     * Constructor a un nuevo objeto <code>DateTextField</code> con la fecha del sistema como valor inicial
     */
    public DateTextField() {
	this( new Date() );
    }



    /**
     * Obtiene el valor de la propiedad fecha
     * @return el valor de la propiedad fecha
     */
    public Date getDate() {
	return date;
    }



    /**
     * estable los valores de la propiedad fecha
     * @param date nuevo valor de la propiedad fecha
     */
    public void setDate( Date date ) {
	Date old = this.date;
	this.date = date;
	setText( DATE_FORMAT.format(date) );
	firePropertyChange( "date", old, date );
    }
}


/*
jFormattedTextField1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jFormattedTextField1MouseClicked(evt);
            }
        });
        
        
         private void jFormattedTextField1MouseClicked(java.awt.event.MouseEvent evt) {                                                  
// TODO add your handling code here:
        if (evt.getButton()==evt.BUTTON3)
            JOptionPane.showMessageDialog(this,"dd");
    }   */